package org.yutian.springboot.controller;

import org.springframework.web.bind.annotation.*;
import org.yutian.springboot.vo.ForumListTopicReq;
import org.yutian.springboot.vo.ForumListTopicRsp;
import org.yutian.springboot.vo.HttpResponse;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/forum")
public class ForumController {

//    @RequestMapping("topics")
//    public HttpResponse listTopic(ForumListTopicReq req) {
//        //显示主帖列表
//        List<ForumListTopicRsp> res = new ArrayList<>();
//        res.add(new ForumListTopicRsp());
//        return HttpResponse.createSuc(res);
//    }

//    @RequestMapping("topics")
//    public Map listTopic(ForumListTopicReq req) {
//        //显示主帖列表
//        List<ForumListTopicRsp> res = new ArrayList<>();
//        res.add(new ForumListTopicRsp());
//        HashMap<String, Object> map = new HashMap();
//        map.put("data", res);
//        return map;
//    }

    @RequestMapping("topics")
    public List listTopic(ForumListTopicReq req) {
        //显示主帖列表
        List<ForumListTopicRsp> res = new ArrayList<>();
        res.add(new ForumListTopicRsp());
        return res;
    }

    @RequestMapping("/hello")
    String home(@RequestParam("msg") String msg) {
        return "Hello World!" + msg;
    }

//    @GetMapping("topics")
//    public String listTopics() {
//        //显示主帖列表
//        return "topiclist";
//    }

    @GetMapping("topic/{topicId:[0-9]+}")
    public String showTopic(@PathVariable("topicId") int topicId) {
        //显示单个主帖和它的跟贴
        return "topic";
    }

    @GetMapping("topic/{topicId:[0-9]+}/comment/{commentId:[0-9]+}")
    public String showComment(@PathVariable("topicId") int topicId, @PathVariable("commentId") int commentId) {
        //显示单个跟贴
        return "comment";
    }

    @PostMapping("topic")
    public String createTopic(@RequestBody Map<String, Object> content){
        //创建一个主帖
        return "topic";
    }
    @PostMapping("topic/{topicId:[0-9]+}/comment")
    public String createComment(@PathVariable("topicId") int topicId, @RequestBody String content){
        //创建一个跟贴
        return "comment";
    }
}